<?php

/**
 * 同步有赞订单，每半个小时同步一次
 *
 **/

ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\service\SuperSubsidy\YouZanOrder;

$hours = $argv[1] ?? 1;
$tid = $argv[2] ?? '';
var_dump('查询更新订单');
$endUpdate = date('Y-m-d H:i:s');
$startUpdate = date('Y-m-d H:i:s', strtotime('-' . $hours . ' hours', strtotime($endUpdate)));
$endUpdate = date('Y-m-d H:i:s', strtotime($endUpdate) + 600);
list($allCount, $searchAlltids) = YouZanOrder::searchCreateOrder($startUpdate, $endUpdate, $tid, true);
var_dump('更新' . $allCount . '条订单');

var_dump('查询退款的订单');
$startUpdate = strtotime('-' . $hours . ' hours');
$endUpdate = time();
list($count, $searchRefundtids) = YouZanOrder::searchRefundOrders($startUpdate, $endUpdate, true, $searchAlltids);
var_dump('更新' . $count . '条发生退款订单');